#include "Application.h"
#include "Runtime/Engine/2D/SlaveRenderer.h"
#include "Runtime/Platform/Windows/WindowsPlatformMisc.h"

namespace Alice
{
    GenericApplication*Application::mPlatformApplication=nullptr;
    Application*Application::mCurrentApplication=nullptr;
    void Application::Create()
    {
        mPlatformApplication=PlatformMisc::CreateApplication();
        mCurrentApplication=new Application;
    }
    Window* Application::AddWindow(Window* InSlateWindow, const bool bShowImmediately)
    {
        GenericWindow*newWindow=MakeWindow(InSlateWindow,bShowImmediately);
        return InSlateWindow;
    }
    GenericWindow* Application::MakeWindow(Window* InSlateWindow, const bool bShowImmediately)
    {
        GenericWindow*newWindow=mPlatformApplication->MakeWindow();
        InSlateWindow->SetNativeWindow(newWindow);
        mPlatformApplication->InitializeWindow(newWindow,nullptr,bShowImmediately);
        return newWindow;
    }
    void Application::Tick(ESlateTickType inTickType)
    {
        if(EnumHasAnyFlags(inTickType,ESlateTickType::PlatformAndInput))
        {
            TickPlatform(0.0f);
        }
    }
    void Application::TickPlatform(float DeltaTime)
    {
        mPlatformApplication->PumpMessages(DeltaTime);
    }
    bool Application::InitializeRenderer(SlaveRenderer* inRenderer, bool bQuietMode)
    {
        mSlaveRenderer=inRenderer;
        mSlaveRenderer->Initialize();
        return true;
    }

}
